<?php

require_once 'Framework/Controller/Action.php';
require_once 'application/models/User/Another.php';
require_once 'application/models/User/Guest.php';
require_once 'application/models/User/Admin.php';

class UserListController extends Framework_Controller_Action

{ 
	private $_user;
	private $_conf;
	
    public function init()
    {
    	$this->_conf = Framework_Registry::get('config');
    	$this->view->adminnum = $this->session->get('adminnum');
    	if (!$this->session->get('authorize'))	{
			$this->_redirect('/admin/');
		}
        $this->_user = new User_Another(1);//fake for constructor
		$this->view->current_page="user";
    }
	
    public function indexAction()
    {
        $this->render();
    }
	
	public function allAction()
	{
		$order = get_value($this->_getParam(0,null));
		$desc = get_value($this->_getParam(1,null));
		if ($desc!==null)
			$page = $this->_getParam(2,0);
		else
			$page = $this->_getParam(0,0);
		$l = $page; 
		$p = $onpage = $this->_conf->admin->on_page;
		$users = User_Another::getUserList($order,$desc,$l,$p,$pages);
		$this->view->users = $users;
		$adduri = ( isset($order) ) ? $order.'/'.$desc.'/' : '';
		$this->view->uri = $adduri;
		$this->view->pages = $pages;
		$this->view->page = $page; 
		$this->render();
	}
	
	public function allguestsAction()
	{
		$order = get_value($this->_getParam(0,null));
		$desc = get_value($this->_getParam(1,null));
		if ($desc!==null)
			$page = $this->_getParam(2,0);
		else
			$page = $this->_getParam(0,0);
		$l = $page; 
		$p = $onpage = $this->_conf->admin->on_page;
		$this->view->guests = User_Guest::getAllGuests($order,$desc,$l,$p,$pages);
		$adduri = ( $desc!==null ) ? $order.'/'.$desc.'/' : '';
		$this->view->uri = $adduri;
		$this->view->pages = $pages;
		$this->view->page = $page; 
		$this->render();
	}
	
	public function profileAction()
	{
		$this->_user = new User_Another(get_value($this->_getParam(0)));
		$this->view->user = $this->_user->getAllData();
		$this->view->abuses = $this->_user->getAllAbuse();
		$this->render();
	}
	
	public function profileguestAction()
	{
		$this->_user = new User_Another(get_value($this->_getParam(0)));
		$this->view->user = $this->_user->getAllData();
		$this->render();
	}
	
	public function blockAction()
	{
		$userId =get_value($this->_getParam(0));
		$this->_user->setUserBlock($userId);
		$this->_redirect('/admin/userlist/profile/'.$userId);
	}
	
	public function unblockAction()
	{
		$userId =get_value($this->_getParam(0));
		$this->_user->setUserUnBlock($userId);
		$this->_redirect('/admin/userlist/profile/'.$userId);
	}
	
	public function blockGuestAction()
	{
		$userId =get_value($this->_getParam(0));
		$this->_user->setUserBlock($userId);
		$this->_redirect('/admin/userlist/profileguest/'.$userId);
	}
	
	public function unblockguestAction()
	{
		$userId =get_value($this->_getParam(0));
		$this->_user->setUserUnBlock($userId);
		$this->_redirect('/admin/userlist/profileguest/'.$userId);
	}
	
	public function increaseAction()
	{
		$userId =get_value($this->_getParam(0));
		User_Admin::increaseUserRating($userId);
		$this->_redirect('/admin/userlist/profile/'.$userId);
	}
	
	public function showonhomeAction()
	{
		$userId = get_value($this->_getParam(0));
		User_Admin::showOnHome($userId);
		$this->_redirect('/admin/userlist/profile/'.$userId);
	}
	
}